package leecode

import "math"

func nthSuperUglyNumber(n int, primes []int) int {
	dp := make([]int, n)
	dp[0] = 1
	for i := 1; i < n; i++ {
		temp := math.MaxInt
		for j := 0; j < i; j++ {
			for k := 0; k < len(primes); k++ {
				if dp[j]*primes[k] > dp[i-1] {
					temp = min(temp, dp[j]*primes[k])
				}
			}
		}
		dp[i] = temp
	}
	return dp[len(dp)-1]
}
